package com.witframework.web.tag;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import com.witframework.util.HtmlBuilder;

/**
 * 框架内置的“全字段”检索html工具按钮标签
 * 用于在实体数据的所有可检索字段上进行模糊匹配检索。
 * <P>
 * 由于该检索域的html代码输入域名称使用了“_s_anonyme”,因此其他html输入域的名称应该避免使用这一名称。
 * @author wuxinyang
 *
 */
public class FullTextSearchTag extends TagSupport{
	//Used to display a ICON.
	private String image="/images/system/search.png";
	//Search use form‘s action to query data.default is "ec"
	private String form="ec";	
	//The class attribute [class=].
	private String styleClass="searchInput";
	
	private String button="fasle";
	@Override
	public int doStartTag() throws JspException {	
		HttpServletRequest request=(HttpServletRequest)pageContext.getRequest();
		String anonyme_value=(String)request.getParameter("_s_anonyme");
		String img=getImage();
		if(img.startsWith("/")){
			img=request.getContextPath()+img;
		}		
		HtmlBuilder html=new HtmlBuilder();
		html.span().id("searchBar").close();	
		
		html.input().name("_s_anonyme");	
		html.value(anonyme_value==null?"":anonyme_value);
		html.styleClass(styleClass);
		html.id("fullSearch");
		html.close();		
		
		if(button.equalsIgnoreCase("true")){
			html.input().type("button").title("查 找").src(img);
			html.align("middle").style("border: 0px solid #fff");
			html.onclick("return queryEc(document.forms."+getForm()+");");		
			html.close();		
		}
		html.spanEnd();		
		
		JspWriter writer = pageContext.getOut();
		try {
			writer.println(html.toString());			
		} catch (IOException e) {
			throw new JspException("Print/Flush in LoadingTag tag error:" + e);
		}
		return (EVAL_BODY_INCLUDE);
	}
	public String getImage() {
		return image;
	}
	public void setImage(String image) {
		this.image = image;
	}
	public String getForm() {
		return form;
	}
	public void setForm(String form) {
		this.form = form;
	}	
	public String getStyleClass() {
		return styleClass;
	}
	public void setStyleClass(String styleClass) {
		this.styleClass = styleClass;
	}
	public String getButton() {
		return button;
	}
	public void setButton(String button) {
		this.button = button;
	}	
}
